<?php
namespace App\Listener;

use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Event\Annotation\Listener;

/**
 * @Listener 
 */
class OrderShopProductListener implements ListenerInterface
{
    public function listen(): array
    {
        return [
            \App\Event\Order\CreateEvent::class,
        ];
    }
    
    // 缓存订单商品信息和店铺信息
    public function process($event)
    {
        $event->order->save([
            'shop_id'       => $event->user->shop_id,
            'daili_id'      => $event->product->daili_id,
            'product_name'  => $event->product->name,
            'product_image' => $event->product->images[0] ?? ''
        ]);
    }
}